import org.apache.commons.codec.digest.DigestUtils as DU

/*
* @ author: karim daher
* @ date: 04-28-2008
* @version: 0.1
 */

class BootStrap {


     def init = { servletContext ->

         def computer = new Category(title:"Accounting", parent:null)
         computer.save()
         def java = new Category(title:"Java developpers", parent:null)
         java.save()
         def net = new Category(title:".NET developpers", parent:null)
         net.save()
         def education = new Category(title:"Academic/Education/Training", parent:null)
         education.save()
         //new Category(title:"Administrative").save()
         def health = new Category(title:"Healthcare", parent:null)
         health.save()
         def adminstration =  new Category(title:"Administration", parent:null)
         adminstration.save()

        //Expertise list
        def javaExp = new Expertise(title:"Java Devellopement").save()
        def grailsExp = new Expertise(title:"Grails, Groovy").save()
        new Expertise(title:"Network security").save()
        new Expertise(title:"Java security").save()
        new Expertise(title:"Java, J2EE").save()

        def usrRole = new Authority(authority:"ROLE_USER",description:"User role")
        usrRole.save()
		def moderatorRole = new Authority(authority:"ROLE_MODERATOR",description:"Moderator role")
         moderatorRole.save()
		def adminRole = new Authority(authority:"ROLE_ADMINISTRATOR",description:"Administrator role")
		adminRole.save()
		def suspendedRole = new Authority(authority:"ROLE_SUSPENDED",description:"Suspended role")
        suspendedRole.save()
        def supervisorRole = new Authority(authority:"ROLE_SUPERVISOR",description:"Supervisor role")
        supervisorRole.save()


         new Requestmap(url:"/user/show/**",configAttribute:"ROLE_USER,ROLE_ADMINISTRATOR").save()
         new Requestmap(url:"/user/list/**",configAttribute:"ROLE_USER,ROLE_ADMINISTRATOR").save()
         new Requestmap(url:"/user/update/**",configAttribute:"ROLE_USER,ROLE_ADMINISTRATOR").save()
         new Requestmap(url:"/content/create/**",configAttribute:"ROLE_USER,ROLE_ADMINISTRATOR").save()
         new Requestmap(url:"/content/edit/**",configAttribute:"ROLE_USER,ROLE_ADMINISTRATOR").save()


        def profile = new MemberProfile()
         profile.save()
         println "Empty Profile created : " + profile?.id

        def admin = new Person(username:"admin",
                 userRealName:"System admin",
                 email:"admin@syste.com",
                 passwd:"${DU.md5Hex("123456")}",
                 enabled:true,
                 email_show:true,
                 description:"Administrator",
                 state:"Quebec",
                 country:"Canada",
                 zipCode:"A1A1A1", referedBy:null
                 ,profile:profile)
         admin.save()
         admin.addToAuthorities(usrRole)
         admin.addToAuthorities(moderatorRole)
         admin.addToAuthorities(adminRole)


         def list = ["Java", "Modeling"]
         def prof1 = new MemberProfile(title:"Java developper"
                    ,resume:"<b>Intermediate Java Developper</b><br>bla bal bla")
         prof1.save()
         prof1.addToCategories(java)
         prof1.addToExpertise(grailsExp)
         prof1.addToExpertise(javaExp)

        def karimUser = new Person(username:"karim",
                 userRealName:"Karim Karim",
                 email:"karim@syste.com",
                 passwd:"${DU.md5Hex("123456")}",
                 enabled:true,
                 email_show:true,
                 description:"Java Developer",
                 //gender:"Male",
                 state:"Quebec",
                 country:"Canada",
                 zipCode:"H3T1G1", referedBy:admin
            ,profile:prof1)
             karimUser.save()
         karimUser.addToAuthorities(usrRole)
         karimUser.save()
     }
     def destroy = {
     }
} 